Dokumentaro de Gambaso
Compilation & Installation
Components
gb
Array
Error
gb.crypt
gb.qt4
Documents
Indekso de Lingvo
Language Overviews
LeguMin
Lexicon
Registro

Object[].Sort (gb)

Function Sort ( [ Mode As Integer ] ) As Object[]

Sort the array and return it.

Mode can have the following value:

gb.Ascent Ascent sort. This is the default value.
gb.Descent Descent sort.

Objects are compared by calling the special public method _compare.

This method is called on one object, and takes one argument, the reference of the other object it must be compared with.

It must return the result of the comparison as an integer number:
  • 0 if the objects are equal.

  • 1 if the object is greater than the one passed as argument.

  • -1 if the object is lower than the one passed as argument.

If the objects don't implement the special _compare method, then they are compared by using their address in memory.

Examples

' class MyObject
PUBLIC Name as String
PUBLIC Age as Integer

PUBLIC FUNCTION _compare(Other AS MyObject) AS Integer

  RETURN Sgn(Age - Other.Age)

END